package models

import (
	"gorm.io/gorm"
	"time"
)

func (ReportDayAdvertiser) TableName() string {
	return "report_day_advertiser"
}

func (ReportDayAdvertiserJln) TableName() string {
	return "report_day_advertiser_jln"
}

type ReportDayAdvertiserJln struct {
	ReportDayAdvertiser
}

type ReportDayAdvertiser struct {
	ID                 int     `gorm:"primarykey" json:"id"`
	CreateTime         string  `json:"create_time"`
	UpdateTime         string  `json:"update_time"`
	MediaId            int     `json:"media_id,omitempty"`
	CompanyId          int     `json:"company_id,omitempty"`
	MediaAccountId     int     `json:"media_account_id,omitempty"`
	AdvertiserId       int64   `json:"advertiser_id"`
	AdvertiserName     string  `json:"advertiser_name"`
	Tdate              string  `json:"tdate"`
	PayAmountRoi       float64 `json:"pay_amount_roi,omitempty"`
	ValidPlay          int64   `json:"valid_play,omitempty"`
	TotalPlay          int64   `json:"total_play,omitempty"`
	Click              int64   `json:"click,omitempty"`
	Show               int64   `json:"show,omitempty"`
	Convert            int64   `json:"convert,omitempty"`
	Cost               float64 `json:"cost,omitempty"`
	ConvertCost        float64 `json:"convert_cost,omitempty"`
	StatPayAmount      float64 `json:"stat_pay_amount,omitempty"`
	Cpc                float64 `json:"cpc,omitempty"`
	Ctr                float64 `json:"ctr,omitempty"`
	Cpm                float64 `json:"cpm,omitempty"`
	OrderCount         int     `json:"order_count,omitempty"`
	OrderCost          string  `json:"order_cost,omitempty"`
	InAppOrderGmv      float64 `json:"in_app_order_gmv,omitempty"`
	InAppOrderRoi      float64 `json:"in_app_order_roi,omitempty"`
	PlayDuration3s     int64   `json:"play_duration_3s,omitempty" gorm:"column:play_duration_3s"`
	PlayDuration3sRate float64 `json:"play_duration_3s_rate,omitempty" gorm:"column:play_duration_3s_rate"`
}

// BeforeCreate GORM 的钩子函数，会在创建记录前被调用
func (r *ReportDayAdvertiser) BeforeCreate(tx *gorm.DB) (err error) {
	r.CreateTime = time.Now().Format(time.DateTime) // 设置当前时间
	r.UpdateTime = time.Now().Format(time.DateTime) // 设置当前时间
	return nil
}

func (r *ReportDayAdvertiser) BeforeUpdate(tx *gorm.DB) (err error) {
	r.UpdateTime = time.Now().Format(time.DateTime) // 设置当前时间
	return nil
}
